﻿using Api.Application.Command.City;
using Api.DTO;
using AutoMapper;
using Domain;
using ErrorCode;
using Infrastructure;
using MediatR;
using System.Security.Cryptography;

namespace Api.Application.Handler.City
{
    public class ShowCityHandler : IRequestHandler<ShowCityCommand, ApiPaging<CityDTO>>
    {
        private readonly IBase<CityModel> cityRepo;
        private readonly IMapper mapper;

        public ShowCityHandler(IBase<CityModel> cityRepo, IMapper mapper)
        {
            this.cityRepo = cityRepo;
            this.mapper = mapper;
        }
        public Task<ApiPaging<CityDTO>> Handle(ShowCityCommand request, CancellationToken cancellationToken)
        {
            ApiPaging<CityDTO> paging = new ApiPaging<CityDTO>();
            var province = cityRepo.GetAll().Where(x => x.ProvinceId == request.ProvinceId);
            var provinces = mapper.Map<List<CityDTO>>(province);
            paging.Code = ApiEnum.OK;
            paging.Msg = "获取市成功";
            paging.Data = provinces;
            return Task.FromResult(paging);
        }
    }
}
